package com.bwie.service.impl;

import cn.hutool.core.io.FileUtil;
import com.bwie.mapper.UserHotelMapper;
import com.bwie.utils.R;
import com.github.tobato.fastdfs.domain.StorePath;
import com.github.tobato.fastdfs.service.FastFileStorageClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bwie.mapper.HotelMapper;
import com.bwie.pojo.Hotel;
import com.bwie.service.HotelService;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * @Author: zhang
 * @Date:  2025/7/4 19:13
 * @Description: 
 **/
@Service
public class HotelServiceImpl extends ServiceImpl<HotelMapper, Hotel> implements HotelService {

    @Autowired
    private HotelMapper hotelMapper;

    @Autowired
    private FastFileStorageClient fastFileStorageClient;
    @Override
    public List<Hotel> selectAll(Long id) {
        List<Hotel> hotelList = hotelMapper.selelctAll(id);
        return hotelList;

    }

    @Override
    public R uploadImage(MultipartFile file) {

        try {
        String extName = FileUtil.extName(file.getOriginalFilename());
            StorePath storePath = fastFileStorageClient.uploadFile(file.getInputStream(), file.getSize(), extName, null);
            String Url = "http://192.168.80.192:8888/"+storePath.getFullPath();
            return R.OK(Url);
        } catch (IOException e) {
            e.printStackTrace();
            return R.ERROR(500,"上传失败");
        }

    }

    @Override
    public R updateHotel(Hotel hotel) {
        hotelMapper.updateById(hotel);
        return R.OK(hotel);
    }
}
